<?php
/*
	精彩相册
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'show';
set_html('title','精彩相册');
if($_RQ['op']=='show'){
	$mid=intval($_RQ['mid']);
	if(!$mid){
		$mid=$_SESSION['uid'];
	}
	$list=$this->getall('photo',array('mid'=>$mid),array('image'),'image');
	if(!$list){
		$list=array();
	}
	$list=array_keys($list);
	foreach($list as &$image){
		$image=tomedia($image);
	}
	$item=$this->get('card',array('mid'=>$mid));
	$item['num']=count($list);
	$item['photos']=implode(',',$list).',';
	$item['first']=$list['0'];
	$sharedata=array(
		'title'=>$item['name'],
		'desc'=>$item['qianming']?:'您好，我是'.$item['name'],
		'link'=>custom_url('jy_business_card/index//mid='.$mid,true),
		'imgUrl'=>$item['avatar'],
	);
	$return['sharedata']=$sharedata;
	$return['item']=$item;
	$return['htmls']=$this->template_url('photo_show');
	exi($return);
}
if($_RQ['op']=='edit'){
	$list=$this->getall('photo',array('mid'=>$_SESSION['uid']));
	if(!$list){
		$list=array();
	}
	$return['item']=array('list'=>$list);
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$list=$post['list'];
	foreach($list as $item){
		if($item['del']){
			if($item['id']){
				$this->delete('photo',array('id'=>intval($item['id']),'mid'=>$_SESSION['uid']));
			}
			continue;
		}else{
			if(!$item['id']){
				$new=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$_SESSION['uid'],
					'image'=>trim($item['image']),
				);
				$this->insert('photo',$new);
			}
		}
	}
	exi('设置成功！','','goback');
}